<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" placeholder="请输入一个数字" class="ipt1" />
    <button>判断是否为水仙花数</button> <input type="text" class="ipt2" />
  </body>
</html>
<script>
  var oIpt1 = document.querySelector(".ipt1");
  var oBtn = document.querySelector("button");
  var oIpt2 = document.querySelector(".ipt2");
  oBtn.onclick = function () {
    var g = oIpt1.value % 10;
    var s = parseInt((oIpt1.value / 10) % 10);
    var b = parseInt(oIpt1.value / 100);
    if (g * g * g + s * s * s + b * b * b == oIpt1.value) {
      oIpt2.value = oIpt1.value + "为水仙花数字";
    } else {
      oIpt2.value = oIpt1.value + "不为水仙花数字";
    }
  };
</script>
